package com.example.onlineeducation.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.example.onlineeducation.base.BaseViewModel
import com.example.onlineeducation.data.json.LoginJson
import com.example.onlineeducation.data.json.VersionJson
import com.example.onlineeducation.repository.UserRepository
import com.example.onlineeducation.repository.VersionRepository
import com.yc.jetpacklib.net.YcResult
import kotlinx.coroutines.flow.collectLatest


/**
 * Creator: sindi
 * Date: 2022/01/05
 * UseDes:
 */
class WelcomeVM : BaseViewModel() {

    private val mVersionRepository: VersionRepository by lazy { VersionRepository(mApiService) }

    private val _mVersionResult = MutableLiveData<YcResult<VersionJson>>()
    val mVersionResult: LiveData<YcResult<VersionJson>> = _mVersionResult

    /**
     * 获取版本更新信息
     */
    fun checkVersion() = ycLaunch {
        mVersionRepository.getVersion().ycHasLoading().collectLatest {
            _mVersionResult.postValue(it)
        }
    }
}